export interface ShowModalInterface {
  title?: string;
  content: string;
  options?: any;
  successCallback?(arg0?: any, arg1?: any): Promise<any>; //回调函数
  cancelCallback?(arg0?: any, arg1?: any): Promise<any>; //回调函数
}
export const showLoading = (title = "加载中") =>
  uni.showLoading({ title: title, mask: true });

export const hideLoading = () => uni.hideLoading();

export const showToast = (title: string, options = {}) =>
  uni.showToast({ title: title, duration: 2000, icon: "none", ...options });

export const successMsg = (title: string, options = {}) =>
  uni.showToast({ title: title, duration: 2000, icon: "success", ...options });

export const errorMsg = (title: string, options = {}) =>
  uni.showToast({ title: title, duration: 2000, icon: "error", ...options });

export const closeMsg = () => uni.hideToast();

export const showModalMsg = (data: ShowModalInterface) => {
  let params: any = data.options ? { ...data.options } : {};
  params.title = data.title || "提示";
  params.content = data.content;
  uni.showModal({
    ...params,
    success: (res: any) => {
      if (res.confirm) {
        data.successCallback && data.successCallback(res);
      } else if (res.cancel) {
        data.cancelCallback && data.cancelCallback(res);
      }
    },
  });
};
